package com.icss.train_sys_back.mapper.system_manage;

import com.icss.train_sys_back.entity.system_manage.RoleEntity;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author 小泽
 * @createTime 2025/9/29 10:35
 */
@Mapper
public interface RoleManageMapper {
    //分页+条件查询角色列表
    List<RoleEntity> getListConditions(String roleName, String roleDescription);

    //添加角色
    @Insert("insert into t_role values (null,#{roleName},#{roleDescription},#{status},now(),now())")
    boolean add(RoleEntity role);

    //删除角色
    @Delete("delete from t_role where role_id = #{roleId}")
    boolean delete(Integer roleId);

    //更新角色
    @Update("update t_role set role_name = #{roleName},role_description = #{roleDescription},status = #{status},update_time = now() where role_id = #{roleId}")
    boolean update(RoleEntity role);

    //根据角色Id保存对应的权限
    void insertRolePermissions(Integer roleId, List<Integer> permissionIds);

    //根据角色Id获取角色对应的权限Ids
    @Select("select menu_id from t_menu_role where role_id = #{roleId}")
    List<Integer> getRolePermissions(Integer roleId);

    //根据角色Id删除原有的权限
    @Delete("delete from t_menu_role where role_id = #{roleId}")
    boolean deletePermissionsByRoleId(Integer roleId);
    @Select("select * from t_role")
    List<RoleEntity> getAllRoles();
}
